import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yp/config/config.dart';
import 'package:yp/router.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
// import 'package:yp/pages/order_create/widgets/item_widgets2.dart';
// import 'package:timelines/timelines.dart';
// import 'package:yp/widgets/select_button.dart';
// import 'package:yp/pages/order_create/widgets/text_input.dart';
// import 'package:yp/pages/order_create/widgets/select_status.dart';
import 'package:yp/helper.dart';
import 'logic.dart';
import 'state.dart';

class SearchMemberPage extends StatelessWidget {
  final SearchMemberLogic logic = Get.put(SearchMemberLogic());
  final SearchMemberState state = Get.find<SearchMemberLogic>().state;

  @override
  Widget build(BuildContext context) {

    return WillPopScope(
      onWillPop: () async {
        Get.back(result: state.selectMemberData);
        return true;
      },
      child: Scaffold(
          resizeToAvoidBottomInset: false,
          appBar: AppBar(
            backgroundColor: Config.mainColor,
            brightness: Brightness.light,
            iconTheme: IconThemeData(color: Colors.white),
            title: Text(
              "搜索会员",
              style: TextStyle(color: Colors.white, fontSize: 32.sp),
            ),
            centerTitle: true,
            elevation: 0,
          ),
          body: GetBuilder<SearchMemberLogic>(
              builder: (logic) {
                return Column(
                  children: [
                    Container(
                        padding: EdgeInsets.all(30.w,),
                        decoration: BoxDecoration(
                          color: Colors.white,
                        ),
                        child: Row(
                          children: [
                            Container(
                              height: 57.w,
                              width: 590.w,
                              decoration: BoxDecoration(
                                color: Color(0xfffF7F8FA),
                                borderRadius: BorderRadius.all(
                                  Radius.circular(35.w),
                                ),
                              ),
                              child: Center(
                                child: TextField(
                                  controller: state.controller,
                                  textAlignVertical: TextAlignVertical.center,
                                  decoration: InputDecoration(
                                    isDense: true,
                                    prefixIcon: Icon(
                                      Icons.search_rounded,
                                      size: 20,
                                      color: Color(0xfffD2D2D2),
                                    ),
                                    contentPadding: EdgeInsets.all(0),
                                    prefixIconConstraints: BoxConstraints(
                                      maxWidth: 70.w,
                                      minWidth: 70.w,
                                    ),
                                    hintText: '请输入会员手机号',
                                    hintStyle: TextStyle(
                                      fontSize: 26.sp,
                                      color: Color(0xffD2D2D2),
                                    ),
                                    border: InputBorder.none,
                                  ),
                                ),
                              ),
                            ),
                            SizedBox(width: 30.w,),
                            GestureDetector(
                              onTap: () {
                                String phone = state.controller.text;
                                if(phone.isEmpty){
                                  toast("请输入手机号");
                                  return;
                                }
                                if(!RegexUtil.isMobileSimple(phone)){
                                  toast("手机号格式错误");
                                  return;
                                }
                                logic.searchMember();
                              },
                              child: Text(
                                "搜索",
                                style: TextStyle(
                                  fontSize: 32.sp,
                                  color: Color(0xff666666),
                                ),
                              ),
                            ),
                          ],
                        )
                    ),
                    state.searchResultIshow ?
                      Expanded(
                        child: state.searchResult ?
                          ListView(
                            shrinkWrap: true,
                            primary: true,
                            children: [
                              GestureDetector(
                                onTap: () {
                                  logic.selectMember();
                                },
                                child: Column(
                                  children: [
                                    Container(
                                      color: Colors.white,
                                      child: Column(
                                          children: [
                                            ListView.builder(
                                              itemBuilder: (ctx, index) {
                                                return Container(
                                                  height: 98.w,
                                                  margin: EdgeInsets.symmetric(horizontal:30.w),
                                                  padding: EdgeInsets.symmetric(vertical:30.w),
                                                  decoration: BoxDecoration(
                                                    color: Color(0xffFFFFFF),
                                                    border: Border(
                                                      bottom: BorderSide(
                                                        width: 2.w,//宽度
                                                        color: Color(0xffcccccc), //边框颜色
                                                      ),
                                                    ),
                                                  ),
                                                  child: Row(
                                                    children: [
                                                      Text(
                                                        state.memberData["usr_name"] ?? "",
                                                        // model?.shopTitle?? " ",
                                                        style: TextStyle(
                                                          color: Color(0xff222222),
                                                          fontSize: 28.w,
                                                        ),
                                                      ),
                                                      SizedBox(width: 20.w,),
                                                      Text(
                                                          state.memberData["mobile"] ?? " ",
                                                        style: TextStyle(
                                                          color: Color(0xff222222),
                                                          fontSize: 28.w,
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                );
                                              },
                                              shrinkWrap: true,
                                              physics: NeverScrollableScrollPhysics(),
                                              itemCount: 1,
                                            ),
                                          ]
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ]
                        )
                          :
                        Column(
                          children: [
                            Container(
                              width: 750.w,
                              padding: EdgeInsets.symmetric(vertical: 40.w),
                              decoration: BoxDecoration(
                                color: Colors.white,
                              ),
                              child: Column(
                                children: [
                                  RichText(
                                    text: TextSpan(
                                      children: [
                                        TextSpan(
                                          text: '没有找到与',
                                          style: TextStyle(
                                              color: Colors.black, fontSize: 28.sp),
                                        ),
                                        TextSpan(
                                          text: state.controller.text.toString(),
                                          style: TextStyle(
                                              color: Config.mainColor, fontSize: 28.sp),
                                        ),
                                        TextSpan(
                                          text: '相匹配的会员信息~',
                                          style: TextStyle(
                                              color: Colors.black, fontSize: 28.sp),
                                        ),
                                      ],
                                    ),
                                  ),
                                  SizedBox(height:20.w),
                                  Text(
                                    "请点击下方按钮立即注册",
                                    style: TextStyle(
                                      fontSize: 28.w,
                                      color: Colors.black,
                                    ),
                                  ),
                                  SizedBox(height:20.w),
                                  GestureDetector(
                                    onTap: () {

                                      Get.toNamed(RouteConfig.userCreate, parameters: {
                                        "moile": state.controller.text.toString(),
                                      });
                                    },
                                    child:Container(
                                      width: 420.w,
                                      height: 88.w,
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.all(
                                          Radius.circular(44),
                                        ),
                                        border: Border.all(color: Config.mainColor),
                                      ),
                                      child: Center(
                                        child: Text(
                                          "立即注册会员",
                                          style: TextStyle(
                                            fontSize: 32.w,
                                            color: Config.mainColor,
                                          ),
                                        ),
                                      ),
                                    ),
                                  )
                                ],
                              ),
                            ),

                          ]
                        ),
                      ):
                        Container(),
                  ],
                );
              })
      ),
    );
  }
}
